package com.tinckay.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tinckay.common.annotation.Log;
import com.tinckay.common.constant.ProjectConstant;
import com.tinckay.entity.po.PumpWarnLevel;
import com.tinckay.service.PumpWarnLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.extension.api.ApiController;

/**
 * <p>
 * 泵车监测预警阀值 前端控制器
 * </p>
 *
 * @author Jean
 * @since 2018-11-10
 */
@Api(tags = "泵车监测预警阀值管理")
@RestController
@RequestMapping("/pumpWarnLevel")
public class PumpWarnLevelController extends ApiController {

    @Autowired
    private PumpWarnLevelService pumpWarnLevelService;

    @Log("删除泵车监测预警阀值信息")
    @DeleteMapping
    @ApiOperation("删除泵车监测预警阀值信息")
    //@RequiresPermissions("pumpWarnLevel:delete")
    public R delete(@ApiParam("所属泵车编号") @RequestParam String pumpCode) {
        if (StrUtil.isBlank(pumpCode)) {
            return failed("所属泵车编号不能为空.");
        }
        pumpWarnLevelService.removeByPumpCode(pumpCode);
        return success(null);
    }

    @Log("新增泵车监测预警阀值信息")
    @PostMapping
    @ApiOperation("新增泵车监测预警阀值信息")
    //@RequiresPermissions("pumpWarnLevel:add")
    public R add(@RequestBody @Validated(ProjectConstant.Save.class) PumpWarnLevel pumpWarnLevel) {
        return success(pumpWarnLevelService.save(pumpWarnLevel));
    }

    @Log("更新泵车监测预警阀值信息")
    @PutMapping
    @ApiOperation("更新泵车监测预警阀值信息")
    //@RequiresPermissions("pumpWarnLevel:update")
    public R update(@RequestBody @Validated(ProjectConstant.Update.class) PumpWarnLevel pumpWarnLevel) {
        pumpWarnLevelService.updateById(pumpWarnLevel);
        return success(pumpWarnLevel);
    }

    @GetMapping("/list")
    @ApiOperation("分页查询泵车监测预警阀值信息列表")
    //@RequiresPermissions("pumpWarnLevel:list")
    public R<IPage> list(@RequestParam(defaultValue = "1") int current,
                         @RequestParam(defaultValue = "10") int size) {
        IPage<PumpWarnLevel> page = pumpWarnLevelService.page(new Page<>(current, size), null);
        return success(page);
    }

    @GetMapping("/info/{pumpCode}")
    @ApiOperation("获取泵车监测预警阀值信息")
    //@RequiresPermissions("pumpWarnLevel:info")
    public R<PumpWarnLevel> info(@PathVariable("pumpCode") String pumpCode) {
        return success(pumpWarnLevelService.getOne(new QueryWrapper<PumpWarnLevel>().lambda().eq(PumpWarnLevel::getPumpCode, pumpCode)));
    }

}

